# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2025/3/8
desc: 
sample: 
"""
import re

import requests

r = r"\d+"
m = re.findall(r, "a123test")
print(m)
#万能匹配 .+(任意字符1到多个)  .* (0---多个）
reg = r'<getMobileCodeInfoResult>(.+)</getMobileCodeInfoResult>'

str = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' \
      ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">' \
      '<soap:Body><getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/"><getMobileCodeInfoResult>18810703325：北京 北京 北京移动全球通卡' \
      '</getMobileCodeInfoResult></getMobileCodeInfoResponse></soap:Body></soap:Envelope>'

print(re.findall(reg, str)[0])

#分组 ()代表分组
# p = re.compile(reg)
m = re.search(reg,str)
print(m.group(0))
print(m.group(1))

result = m.group(1)
print(result.split('：')[0])
print(result.split('：')[1])

#贪婪 非贪婪 加? 最小匹配
str = 'a123ba456bab'
print(re.findall('a(.+)b', str))
print(re.findall('a(.+?)b', str))

print(re.findall('a(.*)b', str))
print(re.findall('a(.*?)b', str))

resp = requests.get(url='http://www.baidu.com')
result =resp.text
reg = '<link rel="dns-prefetch" href="//(.+?)"/>'
print(re.findall(reg, result))
